#include "Runnable.h"

struct RunnableWorkAround {
	Runnable* param;
};

int threadRunner(void* param) {
	RunnableWorkAround* wa = (RunnableWorkAround*)param;

	Runnable* runnable = wa->param;
	delete wa;

	return runnable->run();
}

HANDLE runThread(Runnable* runnable) {
	// Tecnica de: http://www.codeproject.com/KB/threads/thread_win32.aspx
	RunnableWorkAround* wa = new RunnableWorkAround();
	wa->param = runnable;

	return ::CreateThread(NULL, 0, (unsigned long (__stdcall *)(void *))threadRunner,
			(void *)wa, 0, NULL);
}
